package com.zf.easyexcel.constant;

import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 表头数据 导出头
 * @author Zhou Feng
 */
public enum MergeInfoExportHeaderEnum {
    FIELD_ONE(MergeInfoFieldConstants.FIELD_ONE, 0, "表头1"),
    FIELD_TWO(MergeInfoFieldConstants.FIELD_TWO, 1, "表头2"),
    FIELD_THREE(MergeInfoFieldConstants.FIELD_THREE, 2, "表头3")
    ;

    /**
     * 数据中的字段名称
     */
    private final String fieldName;
    /**
     * 在excel中属于第几列
     */
    private final Integer columnIndex;
    /**
     * 在excel中的表头名称
     */
    private final String headerName;

    MergeInfoExportHeaderEnum(String fieldName, Integer columnIndex, String headerName) {
        this.fieldName = fieldName;
        this.columnIndex = columnIndex;
        this.headerName = headerName;
    }

    /**
     * 获取表头
     */
    public static Map<Integer, String> getHeaderMap() {
        return Arrays.stream(MergeInfoExportHeaderEnum.values())
                .sorted(Comparator.comparing(MergeInfoExportHeaderEnum::getColumnIndex))
                .collect(Collectors.toMap(MergeInfoExportHeaderEnum::getColumnIndex, MergeInfoExportHeaderEnum::getHeaderName, (old, cur)->cur, LinkedHashMap::new));
    }

    /**
     * 获取表头对应的字段属性名
     */
    public static Map<Integer, String> getFieldMap() {
        return Arrays.stream(MergeInfoExportHeaderEnum.values())
                .sorted(Comparator.comparing(MergeInfoExportHeaderEnum::getColumnIndex))
                .collect(Collectors.toMap(MergeInfoExportHeaderEnum::getColumnIndex, MergeInfoExportHeaderEnum::getFieldName, (old, cur)->cur, LinkedHashMap::new));
    }

    public String getFieldName() {
        return fieldName;
    }

    public Integer getColumnIndex() {
        return columnIndex;
    }

    public String getHeaderName() {
        return headerName;
    }
}
